package com.dog.basics.admin.controller.common;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dog.basics.bean.dto.admin.common.CommonProblemAddDto;
import com.dog.basics.bean.dto.admin.common.CommonProblemEditDto;
import com.dog.basics.bean.dto.admin.common.CommonProblemSelectDto;
import com.dog.basics.bean.vo.admin.sys.CommonProblemPageVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.ISysCommonProblemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

/**
 * <p>
 * 常见问题 前端控制器
 * </p>
 *
 * @author fengjukang
 * @since 2019-10-11
 */
@RestController
@Api(value = SwaggerConstants.COMMON+"常见问题", tags = SwaggerConstants.COMMON+"常见问题")
@RequestMapping("/admin/problem")
@AllArgsConstructor
@ApiIgnore
public class SysCommonProblemController {

    private final ISysCommonProblemService isyscommonproblemservice;

    /**
     * 常见问题列表
     *
     * @param page
     * @param dto
     * @return
     * @author guonh
     */
    @GetMapping("/page")
    @ApiOperation(value = "常见问题列表", notes = "admin:problem:page")
    @PreAuthorize("@pms.hasPermission('admin:problem:page')")
    public R<IPage<CommonProblemPageVo>> getCommonProblemPage(PageParam page, CommonProblemSelectDto dto) {
        return R.ok(isyscommonproblemservice.getCommonProblemPage(page, dto));
    }

    /**
     * 常见问题添加
     *
     * @param dto
     * @return
     * @author guonh
     */

    @SysLog("常见问题添加")
    @ApiOperation(value = "常见问题添加", notes = "admin:problem:add")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('admin:problem:add')")
    public R<Boolean> addCommonProblem(@Valid @RequestBody CommonProblemAddDto dto) {
        return R.ok(isyscommonproblemservice.addCommonProblem(dto));
    }


    /**
     * 常见问题修改
     *
     * @param dto
     * @return
     * @author guonh
     */
    @SysLog("常见问题修改")
    @ApiOperation(value = "常见问题修改", notes = "admin:problem:edit")
    @PutMapping("/edit")
    @PreAuthorize("@pms.hasPermission('admin:problem:edit')")
    public R<Boolean> editCommonProblem(@Valid @RequestBody CommonProblemEditDto dto) {
        return R.ok(isyscommonproblemservice.editCommonProblem(dto));
    }

    /**
     * 常见问题删除
     *
     * @param id
     * @return
     * @author guonh
     */
    @SysLog("常见问题删除")
    @ApiOperation(value = "常见问题删除", notes = "admin:problem:del")
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@pms.hasPermission('admin:problem:del')")
    public R<Boolean> delCommonProblem(@PathVariable("id") Long id) {
        return R.ok(isyscommonproblemservice.delCommonProblem(id));
    }


}
